package com.wbdgj.ui.mine;

import android.content.Context;
import android.graphics.Bitmap;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;

import com.wbdgj.R;
import com.wbdgj.base.BaseActivity;
import com.wbdgj.base.BaseApplication;
import com.wbdgj.ui.uitool.ShareBoard;
import com.wbdgj.ui.uitool.ShareBoardlistener;
import com.wbdgj.ui.uitool.SnsPlatform;
import com.wbdgj.utils.dialog.LoadingDialog;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

import butterknife.BindView;
import cn.jiguang.share.android.api.JShareInterface;
import cn.jiguang.share.android.api.PlatActionListener;
import cn.jiguang.share.android.api.Platform;
import cn.jiguang.share.android.api.ShareParams;
import cn.jiguang.share.facebook.Facebook;
import cn.jiguang.share.facebook.messenger.FbMessenger;
import cn.jiguang.share.qqmodel.QQ;
import cn.jiguang.share.qqmodel.QZone;
import cn.jiguang.share.twitter.Twitter;
import cn.jiguang.share.wechat.Wechat;
import cn.jiguang.share.wechat.WechatFavorite;
import cn.jiguang.share.wechat.WechatMoments;
import cn.jiguang.share.weibo.SinaWeibo;
import cn.jiguang.share.weibo.SinaWeiboMessage;

public class LotteryWebViewActivity extends BaseActivity{

    @BindView(R.id.content)
    WebView content;
    @BindView(R.id.tv_topTitle)
    TextView tv_topTitle;
    @BindView(R.id.progressBarLoading)
    ProgressBar mLoadingProgress ;
    private Context context = this;
    private String urlTxt, TITLE, PATH;
    private LoadingDialog dialog;
    @Override
    protected int getLayoutResId() {
        return R.layout.ui_webview;
    }

    @Override
    protected void initView() {
        mLoadingProgress.setMax(100);
        urlTxt = getIntent().getStringExtra("url");
        Log.e("zp", urlTxt);
        TITLE = getIntent().getStringExtra("TITLE");
        tv_topTitle.setText(getIntent().getStringExtra("TITLE"));
        content.getSettings().setMediaPlaybackRequiresUserGesture(false);
        //支持javascript
        content.getSettings().setJavaScriptEnabled(true);
        // 设置可以支持缩放
        content.getSettings().setSupportZoom(true);
        // 设置出现缩放工具
        content.getSettings().setBuiltInZoomControls(false);
        //扩大比例的缩放
        content.getSettings().setUseWideViewPort(true);
        //自适应屏幕
        content.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
        content.getSettings().setLoadWithOverviewMode(true);
        content.loadUrl(urlTxt);

        findViewById(R.id.btn_top_right).setVisibility(View.GONE);

        content.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                //设置加载进度条
                view.setWebChromeClient(new WebChromeClientProgress());
                return true;
            }

            @Override
            public void onPageStarted(WebView view, String url, Bitmap favicon) {

                super.onPageStarted(view, url, favicon);
            }
        });

    }
    private class WebChromeClientProgress extends WebChromeClient{
        @Override
        public void onProgressChanged(WebView view, int progress) {
            if (mLoadingProgress != null) {
                mLoadingProgress.setProgress(progress);
                if (progress == 100) {
                    mLoadingProgress.setVisibility(View.GONE);
                }

            }
            super.onProgressChanged(view, progress);
        }
    }

    /**
     * 按键响应，在WebView中查看网页时，检查是否有可以前进的历史记录。
     */
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event)
    {
        // Check if the key event was the Back button and if there's history
        if ((keyCode == KeyEvent.KEYCODE_BACK) && content.canGoBack())
        {

            // 返回键退回
            content.goBack();
            return true;
        }
        // If it wasn't the Back key or there's no web page history, bubble up
        // to the default
        // system behavior (probably exit the activity)
        return super.onKeyDown(keyCode, event);
    }


}
